const Queue = require('./queue.js')

function printYangHuiFor(n) {
  const queue = new Queue()
  queue.enqueue(1)
  for (let i = 1; i <= n; i++) {
    let output = ''
    let preValue = 0
    for (let j = 0; j < i; j++) {
      const cur = queue.dequeue()
      output += cur + ' '
      const next = cur + preValue
      preValue = cur
      queue.enqueue(next)
    }
    queue.enqueue(1)
    console.log(output)
  }
}

function printYangHuiMark(n) {
  const queue = new Queue()
  queue.enqueue(1)
  queue.enqueue(0)
  for (let i = 1; i <= n; i++) {
    let output = ''
    let preValue = 0
    while (true) {
      let cur = queue.dequeue()
      if (cur === 0) {
        queue.enqueue(1)
        queue.enqueue(0)
        break
      } else {
        output += cur + ' '
        const next = cur + preValue
        preValue = cur
        queue.enqueue(next)
      }
    }
    console.log(output)
  }
}

printYangHuiFor(10)
printYangHuiMark(10)
